package org.xwalk.core;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ApplicationErrorReport;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.graphics.Rect;
import android.net.http.SslCertificate;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Looper;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.KeyEvent;
import android.view.SurfaceView;
import android.view.ViewGroup;
import android.view.View.OnTouchListener;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.ValueCallback;
import android.widget.FrameLayout;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.ref.WeakReference;
import java.util.Map;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.ValueCallback;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;

/**
 * <p>XWalkView represents an Android view for web apps/pages. Thus most of attributes
 * for Android view are valid for this class. Since it internally uses
 * <a href="http://developer.android.com/reference/android/view/SurfaceView.html">
 * android.view.SurfaceView</a> for rendering web pages by default, it can't be resized,
 * rotated, transformed and animated due to the limitations of SurfaceView.
 * Alternatively, XWalkView can be transformed and animated by using
 * <a href="http://developer.android.com/reference/android/view/TextureView.html">
 * TextureView</a>, which is intentionally used to render web pages for animation support.
 * Besides, XWalkView won't be rendered if it's invisible.</p>
 *
 * <p>Crosswalk provides two ways to choose TextureView or SurfaceView:</p>
 * <ol><li>[To Be Deprecated] Set preference key
 * {@link XWalkPreferences#ANIMATABLE_XWALK_VIEW} to true to use TextureView,
 * and vice versa. Notice that all XWalkViews share the same preference value.</li>
 * <li>Application developer can set this attribute for a single XWalkView by XML without
 * impact on other XWalkViews, notice that in this case the value of
 * XWalkPreferences#ANIMATABLE_XWALK_VIEW is invaild for this XWalkView.
 * See below steps for detail:
 *  <ul type="disc">
 *   <li> Create an attrs.xml under res/values/ as below, the attrs name must be "animatable":
 *    <pre>
 *    &lt;?xml version="1.0" encoding="utf-8"?&gt;
 *    &lt;resources&gt;
 *      &lt;declare-styleable name="AnimatableView"&gt;
 *        &lt;attr name="animatable" format="boolean" /&gt;
 *      &lt;/declare-styleable&gt;
 *    &lt;/resources&gt;</pre>
 *   </li>
 *   <li>Add xwalk namespace into activity layout file, such as layout/activity_main.xml.
 *    <pre>
 *    &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 *        xmlns:xwalk="http://schemas.android.com/apk/res-auto"
 *        ......</pre>
 *   </li>
 *   <li>Set xwalk attribute to true or false in the same xml as above. True for TextureView,
 *         false for SurfaceView, and SurfaceView is the default.
 *    <pre>
 *    &lt;org.xwalk.core.XWalkView
 *        android:id="@+id/xwalkview"
 *        android:layout_width="match_parent"
 *        android:layout_height="match_parent"
 *        xwalk:animatable="true" &gt;
 *    &lt;/org.xwalk.core.XWalkView&gt;</pre>
 *   </li>
 *   <li>Use XWalkView in MainActivity.java.
 *    <pre>mXWalkView = (XWalkView) findViewById(R.id.xwalkview);</pre>
 *   </li></ul>
 *   There is debug message on logcat according to your "animatable" values:
 *    "XWalkContent: CompositingSurfaceType is TextureView"
 *   </li></ol>
 *
 * <p>XWalkView needs hardware acceleration to render web pages. As a result, the
 * AndroidManifest.xml of the caller's app must be appended with the attribute
 * "android:hardwareAccelerated" and its value must be set as "true".</p>
 * <pre>
 * &lt;application android:name="android.app.Application" android:label="XWalkUsers"
 *     android:hardwareAccelerated="true"&gt;
 * </pre>
 *
 * <p>Crosswalk provides 2 major callback classes, namely {@link XWalkResourceClient} and
 * {@link XWalkUIClient} for listening to the events related to resource loading and UI.
 * By default, Crosswalk has a default implementation. Callers can override them if needed.</p>
 *
 * <p><strong>Unlike WebView, you shouldn't use XWalkView directly. It must be accompanied with
 * {@link XWalkActivity} or {@link XWalkInitializer}. </strong></p>
 *
 * <p>For example:</p>
 *
 * <pre>
 * import android.content.Intent;
 * import android.os.Bundle;
 * import android.webkit.ValueCallback;
 *
 * import org.xwalk.core.XWalkActivity;
 * import org.xwalk.core.XWalkResourceClient;
 * import org.xwalk.core.XWalkUIClient;
 * import org.xwalk.core.XWalkView;
 * import org.xwalk.core.XWalkWebResourceRequest;
 * import org.xwalk.core.XWalkWebResourceResponse;
 *
 * public class MainActivity extends XWalkActivity {
 *     private XWalkView mXWalkView;
 *
 *     private class MyResourceClient extends XWalkResourceClient {
 *         public MyResourceClient(XWalkView view) {
 *             super(view);
 *         }
 *
 *         &#64;Override
 *         public XWalkWebResourceResponse shouldInterceptLoadRequest(XWalkView view,
 *                 XWalkWebResourceRequest request) {
 *             // Handle it here.
 *             // Use createXWalkWebResourceResponse instead of "new XWalkWebResourceResponse"
 *             // to create the response.
 *             // Similar with before, there are two function to use:
 *             // 1) createXWalkWebResourceResponse(String mimeType, String encoding, InputStream data)
 *             // 2) createXWalkWebResourceResponse(String mimeType, String encoding, InputStream data,
 *             //             int statusCode, String reasonPhrase, Map&lt;String, String&gt; responseHeaders)
 *
 *             return createXWalkWebResourceResponse("text/html", "UTF-8", null);
 *         }
 *     }
 *
 *     private class MyUIClient extends XWalkUIClient {
 *         public MyUIClient(XWalkView view) {
 *             super(view);
 *         }
 *
 *         &#64;Override
 *         public boolean onCreateWindowRequested(XWalkView view, InitiateBy initiator,
 *                 ValueCallback&lt;XWalkView&gt; callback) {
 *             XWalkView newView = new XWalkView(MainActivity.this);
 *             callback.onReceiveValue(newView);
 *             return true;
 *         }
 *     }
 *
 *     &#64;Override
 *     protected void onCreate(Bundle savedInstanceState) {
 *         super.onCreate(savedInstanceState);
 *
 *         // Until onXWalkReady() is invoked, you should do nothing with the
 *         // embedding API except the following:
 *         // 1. Instantiate the XWalkView object
 *         // 2. Call XWalkPreferences.setValue()
 *         // 3. Call mXWalkView.setXXClient(), e.g., setUIClient
 *         // 4. Call mXWalkView.setXXListener(), e.g., setDownloadListener
 *         // 5. Call mXWalkView.addJavascriptInterface()
 *
 *         setContentView(R.layout.activity_main);
 *         mXWalkView = (XWalkView) findViewById(R.id.xwalkview);
 *         mXWalkView.setResourceClient(new MyResourceClient(mXWalkView));
 *         mXWalkView.setUIClient(new MyUIClient(mXWalkView));
 *     }
 *
 *     &#64;Override
 *     public void onXWalkReady() {
 *         // Do anyting with the embedding API
 *
 *         mXWalkView.loadUrl("https://crosswalk-project.org/");
 *     }
 *
 *     &#64;Override
 *     protected void onNewIntent(Intent intent) {
 *         if (mXWalkView != null) {
 *             mXWalkView.onNewIntent(intent);
 *         }
 *     }
 * }
 * </pre>
 */

public class XWalkView  extends FrameLayout   {

    /**
     * Normal reload mode as default.
     * @since 1.0
     */
    public final static int RELOAD_NORMAL = 0;

    /**
     * Reload mode with bypassing the cache.
     * @since 1.0
     */
    public final static int RELOAD_IGNORE_CACHE = 1;

    /**
     * SurfaceView is the default compositing surface which has a bit performance advantage,
     * such as it has less latency and uses less memory.
     * @since 7.0
     */
    public final static String SURFACE_VIEW = "SurfaceView";

    /**
     * Use TextureView as compositing surface which supports animation on the View.
     * @since 7.0
     */
    public final static String TEXTURE_VIEW = "TextureView";

    private ArrayList<Object> constructorTypes;
    private ArrayList<Object> constructorParams;
    private ReflectMethod postWrapperMethod;
    private String mAnimatable;
    
    private static final String ANIMATABLE = "animatable";
    private static final String XWALK_ATTRS_NAMESPACE = "http://schemas.android.com/apk/res-auto";

    private XWalkCoreWrapper coreWrapper;
    private Object bridge;

    protected Object getBridge() {
        return bridge;
    }


    /**
     * Constructs a new XWalkView with a Context object.
     * @param context a Context object used to access application assets.
     * @since 6.0
     */
    public XWalkView(Context context) {
        super(context, null);
        SurfaceView surfaceView = new SurfaceView(context);
        surfaceView.setLayoutParams(new ViewGroup.LayoutParams(0, 0));
        addView(surfaceView);

        constructorTypes = new ArrayList<Object>();
        constructorTypes.add(Context.class);

        constructorParams = new ArrayList<Object>();
        constructorParams.add(context);

        postWrapperMethod = new ReflectMethod(this,
                "postXWalkViewInternalContextConstructor");

        reflectionInit();
    }

    public void postXWalkViewInternalContextConstructor() {
        addView((FrameLayout)bridge, new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.MATCH_PARENT));
        removeViewAt(0);
        new org.xwalk.core.extension.XWalkExternalExtensionManagerImpl(this);
    }

    /**
     * Constructor for inflating via XML.
     * @param context  a Context object used to access application assets.
     * @param attrs    an AttributeSet passed to our parent.
     * @since 1.0
     */
    public XWalkView(Context context, AttributeSet attrs) {
        super(context, attrs);
        if (isInEditMode()) return;
        if (attrs != null)
            mAnimatable = attrs.getAttributeValue(
                    XWALK_ATTRS_NAMESPACE, ANIMATABLE);
        SurfaceView surfaceView = new SurfaceView(context);
        surfaceView.setLayoutParams(new ViewGroup.LayoutParams(0, 0));
        addView(surfaceView);

        constructorTypes = new ArrayList<Object>();
        constructorTypes.add(Context.class);
        constructorTypes.add(AttributeSet.class);

        constructorParams = new ArrayList<Object>();
        constructorParams.add(context);
        constructorParams.add(attrs);

        postWrapperMethod = new ReflectMethod(this,
                "postXWalkViewInternalContextAttributeSetConstructor");

        reflectionInit();
    }

    public void postXWalkViewInternalContextAttributeSetConstructor() {
        addView((FrameLayout)bridge, new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.MATCH_PARENT));
        removeViewAt(0);
        new org.xwalk.core.extension.XWalkExternalExtensionManagerImpl(this);
    }

    /**
     * Constructor for Crosswalk runtime. In shared mode, context isi
     * different from activity. In embedded mode, they're same.
     * @param context  a Context object used to access application assets
     * @param activity the activity for this XWalkView.
     * @deprecated This method is no longer supported
     * @since 1.0
     */
    @Deprecated
    public XWalkView(Context context, Activity activity) {
        super(context, null);
        SurfaceView surfaceView = new SurfaceView(context);
        surfaceView.setLayoutParams(new ViewGroup.LayoutParams(0, 0));
        addView(surfaceView);

        constructorTypes = new ArrayList<Object>();
        constructorTypes.add(Context.class);
        constructorTypes.add(Activity.class);

        constructorParams = new ArrayList<Object>();
        constructorParams.add(context);
        constructorParams.add(activity);

        postWrapperMethod = new ReflectMethod(this,
                "postXWalkViewInternalContextActivityConstructor");

        reflectionInit();
    }

    public void postXWalkViewInternalContextActivityConstructor() {
        addView((FrameLayout)bridge, new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.MATCH_PARENT));
        removeViewAt(0);
        new org.xwalk.core.extension.XWalkExternalExtensionManagerImpl(this);
    }

    /**
     * Load a web page/app from a given base URL or a content.
     * If url is null or empty and content is null or empty, then this function
     * will do nothing.
     * If content is not null, load the web page/app from the content.
     * If content is not null and the url is not set, return "about:blank" if
     * calling {@link XWalkView#getUrl()}.
     * If content is null, try to load the content from the url.
     *
     * It supports URL schemes like 'http:', 'https:' and 'file:'.
     * It can also load files from Android assets, e.g. 'file:///android_asset/'.
     * @param url the url for web page/app.
     * @param content the content for the web page/app. Could be empty.
     * @deprecated This method is deprecated, please use
     *             {@link XWalkView#loadUrl},
     *             {@link XWalkView#loadData} or
     *             {@link XWalkView#loadDataWithBaseURL} instead.
     * @since 1.0
     */
    @Deprecated
    public void load(String url, String content) {
        try {
            loadStringStringMethod.invoke(url, content);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod loadStringStringMethod = new ReflectMethod(null, "load");

    /**
     * Load a web page/app from a given base URL or a content with specified HTTP headers
     * @param url the url for web page/app.
     * @param content the content for the web page/app. Could be empty.
     * @param headers the additional HTTP headers
     * @deprecated This method is deprecated, please use
     *             {@link XWalkView#loadUrl},
     *             {@link XWalkView#loadData} or
     *             {@link XWalkView#loadDataWithBaseURL} instead.
     * @since 6.0
     */
    @Deprecated
    public void load(String url, String content, Map<String, String> headers) {
        try {
            loadStringStringMapMethod.invoke(url, content, headers);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod loadStringStringMapMethod = new ReflectMethod(null, "load");

    /**
     * Loads the given data into this WebView using a 'data' scheme URL.
     *
     * Note that JavaScript's same origin policy means that script running in a
     * page loaded using this method will be unable to access content loaded
     * using any scheme other than 'data', including 'http(s)'. To avoid this
     * restriction, use {@link XWalkView#loadDataWithBaseURL} with an
     * appropriate base URL.
     *
     * The encoding parameter specifies whether the data is base64 or URL
     * encoded. If the data is base64 encoded, the value of the encoding
     * parameter must be 'base64'. For all other values of the parameter,
     * including null, it is assumed that the data uses ASCII encoding for
     * octets inside the range of safe URL characters and use the standard %xx
     * hex encoding of URLs for octets outside that range. For example, '#',
     * '%', '\', '?' should be replaced by %23, %25, %27, %3f respectively.
     *
     * The 'data' scheme URL formed by this method uses the default US-ASCII
     * charset. If you need need to set a different charset, you should form a
     * 'data' scheme URL which explicitly specifies a charset parameter in the
     * mediatype portion of the URL and call {@link
     * XWalkView#loadUrl(String)} instead. Note that the charset
     * obtained from the mediatype portion of a data URL always overrides that
     * specified in the HTML or XML document itself.
     *
     * @param data a String of data in the given encoding
     * @param mimeType the MIME type of the data, e.g. 'text/html'
     * @param encoding the encoding of the data
     * @since 8.0
     */
    public void loadData(String data, String mimeType, String encoding) {
        try {
            loadDataStringStringStringMethod.invoke(data, mimeType, encoding);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod loadDataStringStringStringMethod = new ReflectMethod(null, "loadData");

    /**
     * Loads the given data into this XWalkView, using baseUrl as the base URL
     * for the content. The base URL is used both to resolve relative URLs and
     * when applying JavaScript's same origin policy. The historyUrl is used
     * for the history entry.
     *
     * Note that content specified in this way can access local device files
     * (via 'file' scheme URLs) only if baseUrl specifies a scheme other than
     * 'http', 'https', 'ftp', 'ftps', 'about' or 'javascript'.
     *
     * If the base URL uses the data scheme, this method is equivalent to
     * calling {@link XWalkView#loadData} and the historyUrl is
     * ignored, and the data will be treated as part of a data: URL. If the
     * base URL uses any other scheme, then the data will be loaded into the
     * WebView as a plain string (i.e. not part of a data URL) and any
     * URL-encoded entities in the string will not be decoded.
     *
     * Note that the baseUrl is sent in the 'Referer' HTTP header when
     * requesting subresources (images, etc.) of the page loaded using this method.
     *
     * @param baseUrl the URL to use as the page's base URL. If null defaults to
     *                'about:blank'.
     * @param data a String of data in the given encoding
     * @param mimeType the MIMEType of the data, e.g. 'text/html'. If null,
     *                 defaults to 'text/html'.
     * @param encoding the encoding of the data
     * @param historyUrl the URL to use as the history entry. If null defaults
     *                   to 'about:blank'. If non-null, this must be a valid URL.
     * @since 8.0
     */
    public void loadDataWithBaseURL(final String baseUrl, final String data, final String mimeType, final String encoding, final String historyUrl) {
        try {
            loadDataWithBaseURLStringStringStringStringStringMethod.invoke(baseUrl, data, mimeType, encoding, historyUrl);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod loadDataWithBaseURLStringStringStringStringStringMethod = new ReflectMethod(null, "loadDataWithBaseURL");

    /**
     * Loads the given URL.
     *
     * It supports URL schemes like 'http:', 'https:' and 'file:'.
     * It can also load files from Android assets, e.g. 'file:///android_asset/'.
     *
     * @param url the url for web page/app.
     * @since 8.0
     */
    public void loadUrl(String url) {
        try {
            loadUrlStringMethod.invoke(url);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod loadUrlStringMethod = new ReflectMethod(null, "loadUrl");

    /**
     * Loads the given URL.
     *
     * It supports URL schemes like 'http:', 'https:' and 'file:'.
     * It can also load files from Android assets, e.g. 'file:///android_asset/'.
     *
     * @param url the url for web page/app.
     * @param additionalHttpHeaders the additional headers to be used in the
     *            HTTP request for this URL, specified as a map from name to
     *            value. Note that if this map contains any of the headers
     *            that are set by default by this XWalkView, such as those
     *            controlling caching, accept types or the User-Agent, their
     *            values may be overriden by this XWalkView's defaults.
     * @since 8.0
     */
    public void loadUrl(String url, Map<String, String> additionalHttpHeaders) {
        try {
            loadUrlStringMapMethod.invoke(url, additionalHttpHeaders);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod loadUrlStringMapMethod = new ReflectMethod(null, "loadUrl");

    /**
     * Load a web app from a given manifest.json file. If content is not null,
     * load the manifest.json from the content. If content is null, try to load
     * the manifest.json from the url. Note that url should not be null if the
     * launched path defined in manifest.json is relative.
     *
     * It supports URL schemes like 'http:', 'https:' and 'file:'.
     * It can also load files from Android assets, e.g. 'file:///android_asset/'.
     * @param url the url for manifest.json.
     * @param content the content for manifest.json.
     * @since 1.0
     */
    public void loadAppFromManifest(String url, String content) {
        try {
            loadAppFromManifestStringStringMethod.invoke(url, content);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod loadAppFromManifestStringStringMethod = new ReflectMethod(null, "loadAppFromManifest");

    /**
     * Reload a web app with a given mode.
     * @param mode the reload mode.
     * @since 1.0
     */
    public void reload(int mode) {
        try {
            reloadintMethod.invoke(mode);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod reloadintMethod = new ReflectMethod(null, "reload");

    /**
     * Stop current loading progress.
     * @since 1.0
     */
    public void stopLoading() {
        try {
            stopLoadingMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod stopLoadingMethod = new ReflectMethod(null, "stopLoading");

    /**
     * Get the url of current web page/app. This may be different from what's passed
     * by caller.
     * @return the url for current web page/app.
     * @since 1.0
     */
    public String getUrl() {
        try {
            return (String)getUrlMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return null;
    }

    private ReflectMethod getUrlMethod = new ReflectMethod(null, "getUrl");

    /**
    * Get the resource type of hit place in the current page.
    * @return the result of the hit place in the current page.
    * @since 7.0
    */
    public XWalkHitTestResult getHitTestResult() {
        try {
            return (XWalkHitTestResult) coreWrapper.getWrapperObject(getHitTestResultMethod.invoke());
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return null;
    }

    private ReflectMethod getHitTestResultMethod = new ReflectMethod(null, "getHitTestResult");

    /**
     * Get the content height of current web page/app.
     * NOTE: When page finished loading, it's content size info may not be updated.
     * Pls wait for a while for info updating.
     * @return the height of current web page/app in Css coordinate.
     * @since 7.0
     */
    public int getContentHeight() {
        try {
            return (Integer)getContentHeightMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return 0;
    }

    private ReflectMethod getContentHeightMethod = new ReflectMethod(null, "getContentHeight");

    /**
     * Get the title of current web page/app. This may be different from what's passed
     * by caller.
     * @return the title for current web page/app.
     * @since 1.0
     */
    public String getTitle() {
        try {
            return (String)getTitleMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return null;
    }

    private ReflectMethod getTitleMethod = new ReflectMethod(null, "getTitle");

    /**
     * Get the original url specified by caller.
     * @return the original url.
     * @since 1.0
     */
    public String getOriginalUrl() {
        try {
            return (String)getOriginalUrlMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return null;
    }

    private ReflectMethod getOriginalUrlMethod = new ReflectMethod(null, "getOriginalUrl");

    /**
     * Get the navigation history for current XWalkView. It's synchronized with
     * this XWalkView if any backward/forward and navigation operations.
     * @return the navigation history.
     * @since 1.0
     */
    public XWalkNavigationHistory getNavigationHistory() {
        try {
            return (XWalkNavigationHistory) coreWrapper.getWrapperObject(getNavigationHistoryMethod.invoke());
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return null;
    }

    private ReflectMethod getNavigationHistoryMethod = new ReflectMethod(null, "getNavigationHistory");

    /**
     * Injects the supplied Java object into this XWalkView.
     * Each method defined in the class of the object should be
     * marked with {@link JavascriptInterface} if it's called by JavaScript.
     * @param object the supplied Java object, called by JavaScript.
     * @param name the name injected in JavaScript.
     * @since 1.0
     */
    public void addJavascriptInterface(Object object, String name) {
        try {
            addJavascriptInterfaceObjectStringMethod.invoke(object, name);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                addJavascriptInterfaceObjectStringMethod.setArguments(object, name);
                XWalkCoreWrapper.reserveReflectMethod(addJavascriptInterfaceObjectStringMethod);
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod addJavascriptInterfaceObjectStringMethod = new ReflectMethod(null, "addJavascriptInterface");

    /**
     * Removes a previously injected Java object from this XWalkView. Note that
     * the removal will not be reflected in JavaScript until the page is next
     * (re)loaded. See {@link #addJavascriptInterface}.
     * @param name the name used to expose the object in JavaScript
     * @since 7.0
     */
    public void removeJavascriptInterface(String name) {
        try {
            removeJavascriptInterfaceStringMethod.invoke(name);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                removeJavascriptInterfaceStringMethod.setArguments(name);
                XWalkCoreWrapper.reserveReflectMethod(removeJavascriptInterfaceStringMethod);
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod removeJavascriptInterfaceStringMethod = new ReflectMethod(null, "removeJavascriptInterface");

    /**
     * Evaluate a fragment of JavaScript code and get the result via callback.
     * @param script the JavaScript string.
     * @param callback the callback to handle the evaluated result.
     * @since 1.0
     */
    public void evaluateJavascript(String script, ValueCallback<String> callback) {
        try {
            evaluateJavascriptStringValueCallbackMethod.invoke(script, callback);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod evaluateJavascriptStringValueCallbackMethod = new ReflectMethod(null, "evaluateJavascript");

    /**
     * Clear the resource cache. Note that the cache is per-application, so this
     * will clear the cache for all XWalkViews used.
     * @param includeDiskFiles indicate whether to clear disk files for cache.
     * @since 1.0
     */
    public void clearCache(boolean includeDiskFiles) {
        try {
            clearCachebooleanMethod.invoke(includeDiskFiles);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod clearCachebooleanMethod = new ReflectMethod(null, "clearCache");

    /**
     * Clear the resource cache. Note that it only clear the cache for the specified
     * url.
     * @param url indicate which cache will be cleared.
     * @since 6.0
     */
    public void clearCacheForSingleFile(String url) {
        try {
            clearCacheForSingleFileStringMethod.invoke(url);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod clearCacheForSingleFileStringMethod = new ReflectMethod(null, "clearCacheForSingleFile");

    /**
     * Indicate that a HTML element is occupying the whole screen.
     * @return true if any HTML element is occupying the whole screen.
     * @since 1.0
     */
    public boolean hasEnteredFullscreen() {
        try {
            return (Boolean)hasEnteredFullscreenMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return false;
    }

    private ReflectMethod hasEnteredFullscreenMethod = new ReflectMethod(null, "hasEnteredFullscreen");

    /**
     * Leave fullscreen mode if it's. Do nothing if it's not
     * in fullscreen.
     * @since 1.0
     */
    public void leaveFullscreen() {
        try {
            leaveFullscreenMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod leaveFullscreenMethod = new ReflectMethod(null, "leaveFullscreen");

    /**
     * Pause all layout, parsing and JavaScript timers for all XWalkView instances.
     * It will be called when the container Activity get paused. It can also be explicitly
     * called to pause timers.
     *
     * Note that it will globally impact all XWalkView instances, not limited to
     * just this XWalkView.
     *
     * @since 1.0
     */
    public void pauseTimers() {
        try {
            pauseTimersMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod pauseTimersMethod = new ReflectMethod(null, "pauseTimers");

    /**
     * Resume all layout, parsing and JavaScript timers for all XWalkView instances.
     * It will be called when the container Activity get resumed. It can also be explicitly
     * called to resume timers.
     *
     * Note that it will globally impact all XWalkView instances, not limited to
     * just this XWalkView.
     *
     * @since 1.0
     */
    public void resumeTimers() {
        try {
            resumeTimersMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod resumeTimersMethod = new ReflectMethod(null, "resumeTimers");

    /**
     * Pause many other things except JavaScript timers inside rendering engine,
     * like video player, modal dialogs, etc. See {@link #pauseTimers} about pausing
     * JavaScript timers.
     * It will be called when the container Activity get paused. It can also be explicitly
     * called to pause above things.
     * @since 1.0
     */
    public void onHide() {
        try {
            onHideMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod onHideMethod = new ReflectMethod(null, "onHide");

    /**
     * Resume video player, modal dialogs. Embedders are in charge of calling
     * this during resuming this activity if they call onHide.
     * Typically it should be called when the activity for this view is resumed.
     * It will be called when the container Activity get resumed. It can also be explicitly
     * called to resume above things.
     * @since 1.0
     */
    public void onShow() {
        try {
            onShowMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod onShowMethod = new ReflectMethod(null, "onShow");

    /**
     * Release internal resources occupied by this XWalkView.
     * It will be called when the container Activity get destroyed. It can also be explicitly
     * called to release resources.
     * @since 1.0
     */
    public void onDestroy() {
        try {
            onDestroyMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod onDestroyMethod = new ReflectMethod(null, "onDestroy");

    /**
     * Start another activity to get some data back.
     * Here will start from the current XWalkView Activity,
     * but XWalkView embedder can override this API to do their additional job.
     * @deprecated This method is no longer supported
     */
    @Deprecated
    public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
        try {
            startActivityForResultIntentintBundleMethod.invoke(intent, requestCode, options);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod startActivityForResultIntentintBundleMethod = new ReflectMethod(null, "startActivityForResult");

    /**
     * Pass through activity result to XWalkView. Many internal facilities need this
     * to handle activity result like JavaScript dialog, Crosswalk extensions, etc.
     * See <a href="http://developer.android.com/reference/android/app/Activity.html">
     * android.app.Activity.onActivityResult()</a>.
     * @param requestCode passed from android.app.Activity.onActivityResult().
     * @param resultCode passed from android.app.Activity.onActivityResult().
     * @param data passed from android.app.Activity.onActivityResult().
     * @deprecated This method is no longer supported
     * @since 1.0
     */
    @Deprecated
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        try {
            onActivityResultintintIntentMethod.invoke(requestCode, resultCode, data);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod onActivityResultintintIntentMethod = new ReflectMethod(null, "onActivityResult");

    /**
     * Pass through intents to XWalkView. Many internal facilities need this
     * to receive the intents like web notification. See
     * <a href="http://developer.android.com/reference/android/app/Activity.html">
     * android.app.Activity.onNewIntent()</a>.
     * @param intent passed from android.app.Activity.onNewIntent().
     * @return true if this intent is handled
     * @since 1.0
     */
    public boolean onNewIntent(Intent intent) {
        try {
            return (Boolean)onNewIntentIntentMethod.invoke(intent);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return false;
    }

    private ReflectMethod onNewIntentIntentMethod = new ReflectMethod(null, "onNewIntent");

    /**
     * Save current internal state of this XWalkView. This can help restore this state
     * afterwards restoring.
     * @param outState the saved state for restoring.
     * @return true if the state is saved
     * @since 1.0
     */
    public boolean saveState(Bundle outState) {
        try {
            return (Boolean)saveStateBundleMethod.invoke(outState);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return false;
    }

    private ReflectMethod saveStateBundleMethod = new ReflectMethod(null, "saveState");

    /**
     * Restore the state from the saved bundle data.
     * @param inState the state saved from saveState().
     * @return true if it can restore the state.
     * @since 1.0
     */
    public boolean restoreState(Bundle inState) {
        try {
            return (Boolean)restoreStateBundleMethod.invoke(inState);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return false;
    }

    private ReflectMethod restoreStateBundleMethod = new ReflectMethod(null, "restoreState");

    /**
     * Get the API version of Crosswalk embedding API.
     * @return the string of API level.
     * @since 1.0
     */
    public String getAPIVersion() {
        try {
            return (String)getAPIVersionMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return null;
    }

    private ReflectMethod getAPIVersionMethod = new ReflectMethod(null, "getAPIVersion");

    /**
     * Get the Crosswalk version.
     * @return the string of Crosswalk.
     * @since 1.0
     */
    public String getXWalkVersion() {
        try {
            return (String)getXWalkVersionMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return null;
    }

    private ReflectMethod getXWalkVersionMethod = new ReflectMethod(null, "getXWalkVersion");

    /**
     * Embedders use this to customize their handlers to events/callbacks related
     * to UI.
     * @param client the XWalkUIClient defined by callers.
     * @since 1.0
     */
    public void setUIClient(XWalkUIClient client) {
        try {
            setUIClientXWalkUIClientInternalMethod.invoke(client.getBridge());
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                setUIClientXWalkUIClientInternalMethod.setArguments(new ReflectMethod(client, "getBridge"));
                XWalkCoreWrapper.reserveReflectMethod(setUIClientXWalkUIClientInternalMethod);
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod setUIClientXWalkUIClientInternalMethod = new ReflectMethod(null, "setUIClient");

    /**
     * Embedders use this to customize their handlers to events/callbacks related
     * to resource loading.
     * @param client the XWalkResourceClient defined by callers.
     * @since 1.0
     */
    public void setResourceClient(XWalkResourceClient client) {
        try {
            setResourceClientXWalkResourceClientInternalMethod.invoke(client.getBridge());
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                setResourceClientXWalkResourceClientInternalMethod.setArguments(new ReflectMethod(client, "getBridge"));
                XWalkCoreWrapper.reserveReflectMethod(setResourceClientXWalkResourceClientInternalMethod);
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod setResourceClientXWalkResourceClientInternalMethod = new ReflectMethod(null, "setResourceClient");


    public void setBackgroundColor(int color) {
        try {
            setBackgroundColorintMethod.invoke(color);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod setBackgroundColorintMethod = new ReflectMethod(null, "setBackgroundColor");

    /**
     * Set origin access whitelist.
     * @param url the url for accesssing whitelist.
     * @param patterns representing hosts which the application should be able to access.
     * @since 6.0
     */
    public void setOriginAccessWhitelist(String url, String[] patterns) {
        try {
            setOriginAccessWhitelistStringStringArrayMethod.invoke(url, patterns);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod setOriginAccessWhitelistStringStringArrayMethod = new ReflectMethod(null, "setOriginAccessWhitelist");


    public void setLayerType(int layerType, Paint paint) {
        return;
    }
     /**
     * Set the user agent of web page/app.
     * @param userAgent the user agent string passed from client.
     * @since 5.0
     */
    public void setUserAgentString(String userAgent) {
        try {
            setUserAgentStringStringMethod.invoke(userAgent);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod setUserAgentStringStringMethod = new ReflectMethod(null, "setUserAgentString");

      /**
      * Get the user agent of web page/app.
      * @return the XWalkView's user-agent string.
      * @since 6.0
      */
    public String getUserAgentString() {
        try {
            return (String)getUserAgentStringMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return null;
    }

    private ReflectMethod getUserAgentStringMethod = new ReflectMethod(null, "getUserAgentString");

     /**
     * Set the accept languages of XWalkView.
     * @param acceptLanguages the accept languages string passed from client.
     * @since 5.0
     */
    public void setAcceptLanguages(final String acceptLanguages) {
        try {
            setAcceptLanguagesStringMethod.invoke(acceptLanguages);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod setAcceptLanguagesStringMethod = new ReflectMethod(null, "setAcceptLanguages");

    /**
     * Capture a bitmap of visible content.
     * @param callback callback to call when the bitmap capture is done.
     * @since 6.0
     */
    public void captureBitmapAsync(XWalkGetBitmapCallback callback) {
        try {
            captureBitmapAsyncXWalkGetBitmapCallbackInternalMethod.invoke(callback.getBridge());
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod captureBitmapAsyncXWalkGetBitmapCallbackInternalMethod = new ReflectMethod(null, "captureBitmapAsync");

    /**
     * Get XWalkSettings
     * @return the XWalkSettings object.
     * @since 6.0
     */
    public XWalkSettings getSettings() {
        try {
            return (XWalkSettings) coreWrapper.getWrapperObject(getSettingsMethod.invoke());
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return null;
    }

    private ReflectMethod getSettingsMethod = new ReflectMethod(null, "getSettings");

    /**
     * This method is used by Cordova for hacking.
     * TODO(yongsheng): remove this and related test cases?
     *
     * @param networkUp whether network is available
     */
    public void setNetworkAvailable(boolean networkUp) {
        try {
            setNetworkAvailablebooleanMethod.invoke(networkUp);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod setNetworkAvailablebooleanMethod = new ReflectMethod(null, "setNetworkAvailable");

    /**
     * Get the websocket url for remote debugging.
     * @return the web socket url to remote debug this xwalk view.
     * null will be returned if remote debugging is not enabled.
     * @since 4.1
     */
    public Uri getRemoteDebuggingUrl() {
        try {
            return (Uri)getRemoteDebuggingUrlMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return null;
    }

    private ReflectMethod getRemoteDebuggingUrlMethod = new ReflectMethod(null, "getRemoteDebuggingUrl");

    /**
    * Performs zoom in in this XWalkView.
    * @return true if zoom in succeeds, false if no zoom changes
    * @since 5.0
    */
    public boolean zoomIn() {
        try {
            return (Boolean)zoomInMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return false;
    }

    private ReflectMethod zoomInMethod = new ReflectMethod(null, "zoomIn");

    /**
    * Performs zoom out in this XWalkView.
    * @return true if zoom out succeeds, false if no zoom changes
    * @since 5.0
    */
    public boolean zoomOut() {
        try {
            return (Boolean)zoomOutMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return false;
    }

    private ReflectMethod zoomOutMethod = new ReflectMethod(null, "zoomOut");

    /**
    * Performs a zoom operation in this XWalkView.
    * @param factor the zoom factor to apply.
    * The zoom factor will be clamped to the XWalkView's zoom limits.
    * This value must be in the range 0.01 to 100.0 inclusive.
    * @since 5.0
    */
    public void zoomBy(float factor) {
        try {
            zoomByfloatMethod.invoke(factor);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod zoomByfloatMethod = new ReflectMethod(null, "zoomBy");

    /**
    * Gets whether this XWalkView can be zoomed in.
    * @return true if this XWalkView can be zoomed in
    * @since 5.0
    */
    public boolean canZoomIn() {
        try {
            return (Boolean)canZoomInMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return false;
    }

    private ReflectMethod canZoomInMethod = new ReflectMethod(null, "canZoomIn");

    /**
    * Gets whether this XWalkView can be zoomed out.
    * @return true if this XWalkView can be zoomed out
    * @since 5.0
    */
    public boolean canZoomOut() {
        try {
            return (Boolean)canZoomOutMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return false;
    }

    private ReflectMethod canZoomOutMethod = new ReflectMethod(null, "canZoomOut");

    /**
     * Create a new InputConnection for and InputMethod to interact with the view.
     * The default implementation returns the InputConnection created by ContentView
     * @param outAttrs Fill in with attribute information about the connection
     * @return the new InputConnection
     * @since 5.0
     */
    public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
        try {
            return (InputConnection)onCreateInputConnectionEditorInfoMethod.invoke(outAttrs);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return null;
    }

    private ReflectMethod onCreateInputConnectionEditorInfoMethod = new ReflectMethod(null, "onCreateInputConnection");

    /**
     * Sets the initial scale for this XWalkView.
     * @param scaleInPercent the initial scale in percent.
     * @since 6.0
     */
    public void setInitialScale(int scaleInPercent) {
        try {
            setInitialScaleintMethod.invoke(scaleInPercent);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod setInitialScaleintMethod = new ReflectMethod(null, "setInitialScale");

    /**
     * Return the icon which current page has.
     * @return the favicon of current web page/app.
     * @since 6.0
     */
    public Bitmap getFavicon() {
        try {
            return (Bitmap)getFaviconMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return null;
    }

    private ReflectMethod getFaviconMethod = new ReflectMethod(null, "getFavicon");

    /**
    * Control whether the XWalkView's surface is placed on top of its window.
    * Note this only works when XWalkPreferences.ANIMATABLE_XWALK_VIEW is false.
    * @param onTop true for on top.
    * @since 5.0
    */
    public void setZOrderOnTop(boolean onTop) {
        try {
            setZOrderOnTopbooleanMethod.invoke(onTop);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod setZOrderOnTopbooleanMethod = new ReflectMethod(null, "setZOrderOnTop");

    /**
     * Removes the autocomplete popup from the currently focused form field, if present.
     * Note this only affects the display of the autocomplete popup, it does not remove
     * any saved form data from this WebView's store.
     * This is a poorly named method, but we keep it for historical reasons.
     * @since 6.0
     */
    public void clearFormData() {
        try {
            clearFormDataMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod clearFormDataMethod = new ReflectMethod(null, "clearFormData");

    /**
     * Set the enabled state of this view.
     * @param visibility One of VISIBLE, INVISIBLE, or GONE.
     * @since 6.0
     */
    public void setVisibility(int visibility) {
        if (visibility == View.INVISIBLE) visibility = View.GONE;
        super.setVisibility(visibility);
        setXWalkViewInternalVisibility(visibility);
        setSurfaceViewVisibility(visibility);
    }
    /**
     * Set the enabled state of SurfaceView.
     * @param visibility One of VISIBLE, INVISIBLE, or GONE.
     * @since 6.0
     */
    public void setSurfaceViewVisibility(int visibility) {
        try {
            setSurfaceViewVisibilityintMethod.invoke(visibility);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                setSurfaceViewVisibilityintMethod.setArguments(visibility);
                XWalkCoreWrapper.reserveReflectMethod(setSurfaceViewVisibilityintMethod);
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod setSurfaceViewVisibilityintMethod = new ReflectMethod(null, "setSurfaceViewVisibility");

    /**
     * Set the enabled state of XWalkView.
     * @param visibility One of VISIBLE, INVISIBLE, or GONE.
     * @since 6.0
     */
    public void setXWalkViewInternalVisibility(int visibility) {
        try {
            setXWalkViewInternalVisibilityintMethod.invoke(visibility);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                setXWalkViewInternalVisibilityintMethod.setArguments(visibility);
                XWalkCoreWrapper.reserveReflectMethod(setXWalkViewInternalVisibilityintMethod);
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod setXWalkViewInternalVisibilityintMethod = new ReflectMethod(null, "setXWalkViewInternalVisibility");

    /**
     * Registers the interface to be used when content can not be handled by
     * the rendering engine, and should be downloaded instead. This will replace
     * the current handler.
     * @param listener an implementation of XWalkDownloadListener
     * @since 5.0
     */
    public void setDownloadListener(XWalkDownloadListener listener) {
        try {
            setDownloadListenerXWalkDownloadListenerInternalMethod.invoke(listener.getBridge());
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                setDownloadListenerXWalkDownloadListenerInternalMethod.setArguments(new ReflectMethod(listener, "getBridge"));
                XWalkCoreWrapper.reserveReflectMethod(setDownloadListenerXWalkDownloadListenerInternalMethod);
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod setDownloadListenerXWalkDownloadListenerInternalMethod = new ReflectMethod(null, "setDownloadListener");

    private boolean performLongClickDelegate(){
        return performLongClick();
    }
    private boolean onTouchEventDelegate(MotionEvent event){
        return onTouchEvent(event);
    }

    public boolean onTouchEvent(MotionEvent event) {
        try {
            return (Boolean)onTouchEventMotionEventMethod.invoke(event);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return false;
    }

    private ReflectMethod onTouchEventMotionEventMethod = new ReflectMethod(null, "onTouchEvent");

    private void onScrollChangedDelegate(int l, int t, int oldl, int oldt){
        onScrollChanged(l, t, oldl, oldt);
    }
    private void onFocusChangedDelegate(boolean gainFocus, int direction, Rect previouslyFocusedRect){
        onFocusChanged(gainFocus, direction, previouslyFocusedRect);
    }
    private void onOverScrolledDelegate(int scrollX, int scrollY, boolean clampedX, boolean clampedY){
        onOverScrolled(scrollX, scrollY, clampedX, clampedY);
    }

    public void setOnTouchListener(OnTouchListener l) {
        try {
            setOnTouchListenerOnTouchListenerMethod.invoke(l);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod setOnTouchListenerOnTouchListenerMethod = new ReflectMethod(null, "setOnTouchListener");


    public void scrollTo(int x, int y) {
        try {
            scrollTointintMethod.invoke(x, y);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod scrollTointintMethod = new ReflectMethod(null, "scrollTo");


    public void scrollBy(int x, int y) {
        try {
            scrollByintintMethod.invoke(x, y);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod scrollByintintMethod = new ReflectMethod(null, "scrollBy");

    /**
     * Compute the horizontal range that the horizontal scrollbar represents.
     * @return the range of horizontal scrollbar.
     * @since 6.0
     */
    public int computeHorizontalScrollRange() {
        try {
            return (Integer)computeHorizontalScrollRangeMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return 0;
    }

    private ReflectMethod computeHorizontalScrollRangeMethod = new ReflectMethod(null, "computeHorizontalScrollRange");

    /**
     * Compute the horizontal offset of the horizontal scrollbar's
     * thumb within the horizontal range.
     * @return the horizontal offset of the horizontal scrollbar's thumb.
     * @since 6.0
     */
    public int computeHorizontalScrollOffset() {
        try {
            return (Integer)computeHorizontalScrollOffsetMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return 0;
    }

    private ReflectMethod computeHorizontalScrollOffsetMethod = new ReflectMethod(null, "computeHorizontalScrollOffset");

    /**
     * Compute the vertical range that the vertical scrollbar represents.
     * @return the range of the vertical scrollbar.
     * @since 6.0
     */
    public int computeVerticalScrollRange() {
        try {
            return (Integer)computeVerticalScrollRangeMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return 0;
    }

    private ReflectMethod computeVerticalScrollRangeMethod = new ReflectMethod(null, "computeVerticalScrollRange");

    /**
     * Compute the vertical offset the vertical scrollbar's thumb
     * within the horizontal range.
     * @return the vertical offset of the vertical scrollbar's thumb.
     * @since 6.0
     */
    public int computeVerticalScrollOffset() {
        try {
            return (Integer)computeVerticalScrollOffsetMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return 0;
    }

    private ReflectMethod computeVerticalScrollOffsetMethod = new ReflectMethod(null, "computeVerticalScrollOffset");

    /**
     * Compute the vertical extent of the vertical scrollbar's thumb
     * within the vertical range.
     * @return vertical offset of the vertical scrollbar's thumb.
     * @since 6.0
     */
    public int computeVerticalScrollExtent() {
        try {
            return (Integer)computeVerticalScrollExtentMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return 0;
    }

    private ReflectMethod computeVerticalScrollExtentMethod = new ReflectMethod(null, "computeVerticalScrollExtent");

    /**
     * Get the external extension manager for current XWalkView.
     * Embedders could employ this manager to load their own external extensions.
     * @return the external extension manager.
     */
    public XWalkExternalExtensionManager getExtensionManager() {
        try {
            return (XWalkExternalExtensionManager) coreWrapper.getWrapperObject(getExtensionManagerMethod.invoke());
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return null;
    }

    private ReflectMethod getExtensionManagerMethod = new ReflectMethod(null, "getExtensionManager");

    /**
     * Clears the SSL preferences table stored in response to proceeding with
     * SSL certificate errors.
     * @since 6.0
     */
    public void clearSslPreferences() {
        try {
            clearSslPreferencesMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod clearSslPreferencesMethod = new ReflectMethod(null, "clearSslPreferences");

    /**
     * Clears the client certificate preferences stored in response to
     * proceeding/cancelling client cert requests.
     *
     * @param callback a runnable to be invoked when client certs are cleared
     * @since 6.0
     */
    public void clearClientCertPreferences(Runnable callback) {
        try {
            clearClientCertPreferencesRunnableMethod.invoke(callback);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod clearClientCertPreferencesRunnableMethod = new ReflectMethod(null, "clearClientCertPreferences");

    /**
     * Gets the SSL certificate for the main top-level page or null
     * if there is no certificate (the site is not secure).
     * @return the SSL certificate for the main top-level page.
     * @since 6.0
     */
    public SslCertificate getCertificate() {
        try {
            return (SslCertificate)getCertificateMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return null;
    }

    private ReflectMethod getCertificateMethod = new ReflectMethod(null, "getCertificate");

    /**
     * Registers the listener to be notified as find-on-page operations progress.
     *
     * @param listener an implementation of {@link XWalkFindListener}
     * @since 7.0
     */
    public void setFindListener(XWalkFindListener listener) {
        try {
            setFindListenerXWalkFindListenerInternalMethod.invoke(listener.getBridge());
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                setFindListenerXWalkFindListenerInternalMethod.setArguments(new ReflectMethod(listener, "getBridge"));
                XWalkCoreWrapper.reserveReflectMethod(setFindListenerXWalkFindListenerInternalMethod);
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod setFindListenerXWalkFindListenerInternalMethod = new ReflectMethod(null, "setFindListener");

    /**
     * Finds all instances of find on the page and highlights them asynchronously.
     * Notifies any registered {@link XWalkFindListener}.
     * Successive calls to this will cancel any pending searches.
     *
     * @param searchString the string to find.
     * @since 7.0
     */
    public void findAllAsync(String searchString) {
        try {
            findAllAsyncStringMethod.invoke(searchString);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod findAllAsyncStringMethod = new ReflectMethod(null, "findAllAsync");

    /**
     * Highlights and scrolls to the next match found by {@link #findAllAsync},
     * wrapping around page boundaries as necessary.
     * Notifies any registered {@link XWalkFindListener}.
     * If {@link #findAllAsync} has not been called yet, or if {@link #clearMatches} has been
     * called since the last find operation, this function does nothing.
     *
     * @param forward the direction to search
     * @since 7.0
     */
    public void findNext(boolean forward) {
        try {
            findNextbooleanMethod.invoke(forward);
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod findNextbooleanMethod = new ReflectMethod(null, "findNext");

    /**
     * Clears the highlighting surrounding text matches created by {@link #findAllAsync}.
     *
     * @since 7.0
     */
    public void clearMatches() {
        try {
            clearMatchesMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        
    }

    private ReflectMethod clearMatchesMethod = new ReflectMethod(null, "clearMatches");

    /**
     * Gets the compositing surface type of this XWalkView.
     * @return SurfaceView or TextureView
     * @since 7.0
     */
    public String getCompositingSurfaceType() {
        try {
            return (String)getCompositingSurfaceTypeMethod.invoke();
        } catch (UnsupportedOperationException e) {
            if (coreWrapper == null) {
                throw new RuntimeException("Crosswalk's APIs are not ready yet");
            } else {
                XWalkCoreWrapper.handleRuntimeError(e);
            }
        }
        return null;
    }

    private ReflectMethod getCompositingSurfaceTypeMethod = new ReflectMethod(null, "getCompositingSurfaceType");


    void reflectionInit() {
        XWalkCoreWrapper.initEmbeddedMode();

        coreWrapper = XWalkCoreWrapper.getInstance();
        if (coreWrapper == null) {
            XWalkCoreWrapper.reserveReflectObject(this);
            return;
        }

        int length = constructorTypes.size();
        Class<?>[] paramTypes = new Class<?>[length+1];
        for (int i = 0; i < length; ++i) {
            Object type = constructorTypes.get(i);
            if (type instanceof String) {
                paramTypes[i] = coreWrapper.getBridgeClass((String) type);
                constructorParams.set(i, coreWrapper.getBridgeObject(constructorParams.get(i)));
            } else if (type instanceof Class<?>) {
                paramTypes[i] = (Class<?>) type;
            } else {
                assert(false);
            }
        }

        paramTypes[length] = Object.class;
        constructorParams.add(this);

        ReflectConstructor constructor = new ReflectConstructor(
                coreWrapper.getBridgeClass("XWalkViewBridge"), paramTypes);
        try {
            bridge = constructor.newInstance(constructorParams.toArray());
        } catch (UnsupportedOperationException e) {
            return;
        }

        if (postWrapperMethod != null) postWrapperMethod.invoke();

        loadStringStringMethod.init(bridge, null,
                "loadSuper", String.class, String.class);
        loadStringStringMapMethod.init(bridge, null,
                "loadSuper", String.class, String.class, Map.class);
        loadDataStringStringStringMethod.init(bridge, null,
                "loadDataSuper", String.class, String.class, String.class);
        loadDataWithBaseURLStringStringStringStringStringMethod.init(bridge, null,
                "loadDataWithBaseURLSuper", String.class, String.class, String.class, String.class, String.class);
        loadUrlStringMethod.init(bridge, null,
                "loadUrlSuper", String.class);
        loadUrlStringMapMethod.init(bridge, null,
                "loadUrlSuper", String.class, Map.class);
        loadAppFromManifestStringStringMethod.init(bridge, null,
                "loadAppFromManifestSuper", String.class, String.class);
        reloadintMethod.init(bridge, null,
                "reloadSuper", int.class);
        stopLoadingMethod.init(bridge, null,
                "stopLoadingSuper");
        getUrlMethod.init(bridge, null,
                "getUrlSuper");
        getHitTestResultMethod.init(bridge, null,
                "getHitTestResultSuper");
        getContentHeightMethod.init(bridge, null,
                "getContentHeightSuper");
        getTitleMethod.init(bridge, null,
                "getTitleSuper");
        getOriginalUrlMethod.init(bridge, null,
                "getOriginalUrlSuper");
        getNavigationHistoryMethod.init(bridge, null,
                "getNavigationHistorySuper");
        addJavascriptInterfaceObjectStringMethod.init(bridge, null,
                "addJavascriptInterfaceSuper", Object.class, String.class);
        removeJavascriptInterfaceStringMethod.init(bridge, null,
                "removeJavascriptInterfaceSuper", String.class);
        evaluateJavascriptStringValueCallbackMethod.init(bridge, null,
                "evaluateJavascriptSuper", String.class, ValueCallback.class);
        clearCachebooleanMethod.init(bridge, null,
                "clearCacheSuper", boolean.class);
        clearCacheForSingleFileStringMethod.init(bridge, null,
                "clearCacheForSingleFileSuper", String.class);
        hasEnteredFullscreenMethod.init(bridge, null,
                "hasEnteredFullscreenSuper");
        leaveFullscreenMethod.init(bridge, null,
                "leaveFullscreenSuper");
        pauseTimersMethod.init(bridge, null,
                "pauseTimersSuper");
        resumeTimersMethod.init(bridge, null,
                "resumeTimersSuper");
        onHideMethod.init(bridge, null,
                "onHideSuper");
        onShowMethod.init(bridge, null,
                "onShowSuper");
        onDestroyMethod.init(bridge, null,
                "onDestroySuper");
        startActivityForResultIntentintBundleMethod.init(bridge, null,
                "startActivityForResultSuper", Intent.class, int.class, Bundle.class);
        onActivityResultintintIntentMethod.init(bridge, null,
                "onActivityResultSuper", int.class, int.class, Intent.class);
        onNewIntentIntentMethod.init(bridge, null,
                "onNewIntentSuper", Intent.class);
        saveStateBundleMethod.init(bridge, null,
                "saveStateSuper", Bundle.class);
        restoreStateBundleMethod.init(bridge, null,
                "restoreStateSuper", Bundle.class);
        getAPIVersionMethod.init(bridge, null,
                "getAPIVersionSuper");
        getXWalkVersionMethod.init(bridge, null,
                "getXWalkVersionSuper");
        setUIClientXWalkUIClientInternalMethod.init(bridge, null,
                "setUIClientSuper", coreWrapper.getBridgeClass("XWalkUIClientBridge"));
        setResourceClientXWalkResourceClientInternalMethod.init(bridge, null,
                "setResourceClientSuper", coreWrapper.getBridgeClass("XWalkResourceClientBridge"));
        setBackgroundColorintMethod.init(bridge, null,
                "setBackgroundColorSuper", int.class);
        setOriginAccessWhitelistStringStringArrayMethod.init(bridge, null,
                "setOriginAccessWhitelistSuper", String.class, String[].class);
        setUserAgentStringStringMethod.init(bridge, null,
                "setUserAgentStringSuper", String.class);
        getUserAgentStringMethod.init(bridge, null,
                "getUserAgentStringSuper");
        setAcceptLanguagesStringMethod.init(bridge, null,
                "setAcceptLanguagesSuper", String.class);
        captureBitmapAsyncXWalkGetBitmapCallbackInternalMethod.init(bridge, null,
                "captureBitmapAsyncSuper", coreWrapper.getBridgeClass("XWalkGetBitmapCallbackBridge"));
        getSettingsMethod.init(bridge, null,
                "getSettingsSuper");
        setNetworkAvailablebooleanMethod.init(bridge, null,
                "setNetworkAvailableSuper", boolean.class);
        getRemoteDebuggingUrlMethod.init(bridge, null,
                "getRemoteDebuggingUrlSuper");
        zoomInMethod.init(bridge, null,
                "zoomInSuper");
        zoomOutMethod.init(bridge, null,
                "zoomOutSuper");
        zoomByfloatMethod.init(bridge, null,
                "zoomBySuper", float.class);
        canZoomInMethod.init(bridge, null,
                "canZoomInSuper");
        canZoomOutMethod.init(bridge, null,
                "canZoomOutSuper");
        onCreateInputConnectionEditorInfoMethod.init(bridge, null,
                "onCreateInputConnectionSuper", EditorInfo.class);
        setInitialScaleintMethod.init(bridge, null,
                "setInitialScaleSuper", int.class);
        getFaviconMethod.init(bridge, null,
                "getFaviconSuper");
        setZOrderOnTopbooleanMethod.init(bridge, null,
                "setZOrderOnTopSuper", boolean.class);
        clearFormDataMethod.init(bridge, null,
                "clearFormDataSuper");
        setSurfaceViewVisibilityintMethod.init(bridge, null,
                "setSurfaceViewVisibilitySuper", int.class);
        setXWalkViewInternalVisibilityintMethod.init(bridge, null,
                "setXWalkViewInternalVisibilitySuper", int.class);
        setDownloadListenerXWalkDownloadListenerInternalMethod.init(bridge, null,
                "setDownloadListenerSuper", coreWrapper.getBridgeClass("XWalkDownloadListenerBridge"));
        onTouchEventMotionEventMethod.init(bridge, null,
                "onTouchEventSuper", MotionEvent.class);
        setOnTouchListenerOnTouchListenerMethod.init(bridge, null,
                "setOnTouchListenerSuper", OnTouchListener.class);
        scrollTointintMethod.init(bridge, null,
                "scrollToSuper", int.class, int.class);
        scrollByintintMethod.init(bridge, null,
                "scrollBySuper", int.class, int.class);
        computeHorizontalScrollRangeMethod.init(bridge, null,
                "computeHorizontalScrollRangeSuper");
        computeHorizontalScrollOffsetMethod.init(bridge, null,
                "computeHorizontalScrollOffsetSuper");
        computeVerticalScrollRangeMethod.init(bridge, null,
                "computeVerticalScrollRangeSuper");
        computeVerticalScrollOffsetMethod.init(bridge, null,
                "computeVerticalScrollOffsetSuper");
        computeVerticalScrollExtentMethod.init(bridge, null,
                "computeVerticalScrollExtentSuper");
        getExtensionManagerMethod.init(bridge, null,
                "getExtensionManagerSuper");
        clearSslPreferencesMethod.init(bridge, null,
                "clearSslPreferencesSuper");
        clearClientCertPreferencesRunnableMethod.init(bridge, null,
                "clearClientCertPreferencesSuper", Runnable.class);
        getCertificateMethod.init(bridge, null,
                "getCertificateSuper");
        setFindListenerXWalkFindListenerInternalMethod.init(bridge, null,
                "setFindListenerSuper", coreWrapper.getBridgeClass("XWalkFindListenerBridge"));
        findAllAsyncStringMethod.init(bridge, null,
                "findAllAsyncSuper", String.class);
        findNextbooleanMethod.init(bridge, null,
                "findNextSuper", boolean.class);
        clearMatchesMethod.init(bridge, null,
                "clearMatchesSuper");
        getCompositingSurfaceTypeMethod.init(bridge, null,
                "getCompositingSurfaceTypeSuper");
    }

}
